<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/9
 * Time: 12:47
 */
require_once "Basic.php";
class Plan extends Basic {
    private $planTableName = 'timeBlock.plan';
    public function setPlan($arguments){
        $curDate = date('Y-m-d');

        $res = $this->dbHandle->select($this->planTableName, ['date' => $curDate]);
        if (count($res) === 0){
            $curPlan = [];
            for ($i = 0; $i < 48; $i++){
                array_push($curPlan, '');
            }
            $curPlan[$arguments['index']] = $arguments['color'];
            $res = $this->dbHandle->insert($this->planTableName, ['date' => $curDate, 'plan' => $curPlan]);
        }else{
            $curPlan = array_shift($res);
            $curPlan = $curPlan->plan;
            $curPlan[$arguments['index']] = $arguments['color'];
            $res = $this->dbHandle->update($this->planTableName, ['date' => $curDate], ['plan' => $curPlan]);
        }
        return $res;
    }

    public function getPlan($timeStamp){
        $curDate = date('Y-m-d', $timeStamp);
        $dataRes = $this->dbHandle->select($this->planTableName, ['date' => $curDate]);
        $result = [];
        if (count($dataRes) !== 0){
            $result = array_shift($dataRes);
        }
        return $result;
    }

    public function validatePwd($password){
        $result = 0;
        if(md5(md5($password)) === 'cb94bda9ee792ed501ffed8dff6e4164'){
            $result = 1;
        }
        return $result;
    }
}